package com.maker.generator.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dwork.base.controller.BaseController;
import com.dwork.base.controller.entity.BaseResultObject;
import com.dwork.base.pagination.Page;
import com.dwork.base.pagination.Pagination;
import com.maker.generator.entity.MetaGenDBInfo;
import com.maker.generator.entity.MetaGenObj;
import com.maker.generator.service.IGenService;
@Controller
@RequestMapping(value = "metaGenDBInfo", name = "数据库链接管理")
public class MetaDBInfoController extends BaseController{
	private static Logger logger = LoggerFactory.getLogger(MetaDBInfoController.class);
	@Autowired
	private IGenService genService;
	
	@RequestMapping(value = "/g2manage", name = "进入数据库链接管理界面")
	public ModelAndView manage() {
		ModelAndView mv = getBaseMV("/metaDBInfo/manage");
		return mv;
	}
	
	@RequestMapping(value = "/g2selector", name = "进入数据库选择界面")
	public ModelAndView g2selector() {
		ModelAndView mv = getBaseMV("/metaDBInfo/selector");
		return mv;
	}
	@RequestMapping(value = "/queryList", name = "分页查询元对象")
	@ResponseBody
	public void queryList(Integer pageNum,Integer pageSize , String objName, String objComment) {
		BaseResultObject baseResultObject = new BaseResultObject();
		
		
		Map<String, Object> paramMap = new HashMap<String,Object>();
		Page page = new Page();
		page.setCurrentPage(pageNum);
		page.setPageSize(pageSize);
		
		if(objName!=null&&!objName.equals("")){
			paramMap.put("objNameLike", objName);
		}
		if(objComment!=null&&!objComment.equals("")){
			paramMap.put("objCommentLike", objComment);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		Pagination<MetaGenDBInfo> metaGenDBInfoPage = genService.queryMetaGenDBInfoList(page, paramMap);
		if(metaGenDBInfoPage!=null&&metaGenDBInfoPage.getData()!=null){
			map.put("rows", metaGenDBInfoPage.getData());
			map.put("pageSize", metaGenDBInfoPage.getData().size());
			map.put("total", metaGenDBInfoPage.getPage().getTotalCount());
		}
		baseResultObject.setData(map);
		this.putInToJsonResponse(baseResultObject);
	}
	

}
